<?php
/**
 * Created by PhpStorm.
 * User: edmmss
 * Date: 2018/11/14
 * Time: 14:38
 */

namespace app\modules\staticFactory\controller;

use app\modules\staticFactory\StaticFactory;
use yii\web\Controller;

class DefaultController extends Controller
{
    /**
     * 静态工厂模式示例
     * 与抽象工厂模式类似，此模式用于创建一系列相关或相互依赖的对象。
     *『静态工厂模式』与『抽象工厂模式』的区别在于，只使用一个静态方法来创建所有类型对象
     * 此方法通常被命名为 factory 或 build。
     *
     * @date   2018/11/14
     * @author edmmss
     * @return bool
     */
    public function actionIndex()
    {
        $stringObject = StaticFactory::factory(StaticFactory::TYPE_STRING);
        $numberObject = StaticFactory::factory(StaticFactory::TYPE_NUMBER);

        var_dump($stringObject);
        var_dump($numberObject);

//        StaticFactory::factory('test');
        return true;
    }
}